<?php

namespace app\api\controller;

use app\api\controller\resigter\Bases;
use app\common\controller\Api;
use app\common\model\Message as ModelMessage;

/**
 * 系统消息
 * Class
 * @package
 */
class Message extends Api
{

	protected $noNeedLogin = ['details'];
	protected $noNeedRight = '*';

	/**
	 * 列表
	 */
	public function lists()
	{
		$uid = $this->auth->id;
		$page = $this->request->post('page', 1);
		$pageSize = $this->request->post('page_size', 10);
		$typs = Bases::instance()->user_type($uid);
		$where = "typs in  ({$typs}, 3) and status = 1";
		$ret = ModelMessage::where($where)
			->field("id,title,images,from_unixtime(create_time , '%Y-%m-%d %H:%i:%s') sendTime")
			->order('create_time desc')
			->paginate($pageSize);
		$this->success("请求成功", $ret);
	}

	/**
	 * 详情
	 */
	public function details()
    {
        $id = $this->request->post('id', 0);
        if(!$id){
            $this->error("信息错误！");
        }
        $info = ModelMessage::where('id', $id)->find();
        // $info->images = !empty($info->images) ? config("app_url") . $info->images : '';
        $this->success("请求成功", $info);
    }
}
